package com.itheima.builder;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Director director = new Director();

        Builder builder1 = new Builder1() ;
        Product product1 = director.construct(builder1);
        product1.show();

        Builder builder2 = new Builder2() ;
        Product product2 = director.construct(builder2);
        product2.show();
    }
}

class Director {
    public Product construct(Builder builder) {
        builder.BuildPart();
        return builder.getResult();
    }
}

abstract class Builder {
    public abstract void BuildPart() ;
    public abstract Product getResult() ;
}

class Builder1 extends Builder {

    Product product = new Product() ;

    @Override
    public void BuildPart() {
        product.add("part1");
        product.add("part2");
        product.add("part3");
    }

    @Override
    public Product getResult() {
        return product;
    }
}

class Builder2 extends Builder {

    Product product = new Product() ;

    @Override
    public void BuildPart() {
        product.add("part4");
        product.add("part5");
        product.add("part6");
    }

    @Override
    public Product getResult() {
        return product;
    }
}

class Product {
    List<String> parts = new ArrayList<>() ;
    public void add(String part) {
        parts.add(part) ;
    }
    public void show() {
        parts.forEach(System.out::println);
    }
}
